package com.liaoct.lct.listener;

import java.util.Map;

import com.liaoct.lct.activity.BaseActivity;
import com.liaoct.lct.activity.R;
import com.liaoct.lct.db.DataBaseManagement;
import com.liaoct.lct.fragment.ContactInfoFragment;
import com.liaoct.lct.util.Constant;

import android.app.FragmentTransaction;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

/**
 * 联系人列表点击事件
 * 
 * @author liaoct
 * 
 */
public class ContactListItemClickListener implements OnClickListener {

	private BaseActivity activity;

	private DataBaseManagement db;

	/**
	 * 执行操作的操作码
	 */
	private int handler_code;

	public ContactListItemClickListener(Context context, int handler_code) {
		this.activity = (BaseActivity) context;
		this.handler_code = handler_code;
		db = DataBaseManagement.newInstance(context);
	}

	@Override
	public void onClick(View v) {
		switch (this.handler_code) {
		case Constant.CONTACT_ITEM_CLICK_DIAL:
			break;
		case Constant.CONTACT_ITEM_CLICK_INFO:
			this.activity.getAppHeader().setText(
					this.activity.getResources().getString(
							R.string.linkman_info));
			TextView textView = (TextView) v.findViewById(R.id.contactId);
			String contactId = textView.getText().toString();
			ContactInfoFragment fragment = new ContactInfoFragment();
			FragmentTransaction transcation = activity.getFragmentManager()
					.beginTransaction();
			transcation
					.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
			transcation.replace(R.id.tab_content, fragment);
			transcation.commit();
			Map<String, Object> map = db.queryContactById(contactId);
			fragment.bindData(map);
			break;
		}
	}

}
